﻿#pragma once

#include <any>

namespace CustomFormControl
{
    class ListViewNF : public ListView
    {
    public:
        class ListViewColumnSorter : public System::Collections::IComparer
        {
        private:
            int _columnToSort = 0;

            SortOrder *_orderOfSort;

            CaseInsensitiveComparer *const _objectCompare;

        public:
            virtual ~ListViewColumnSorter()
            {
                delete _orderOfSort;
                delete _objectCompare;
            }

            ListViewColumnSorter();

            int Compare(std::any x, std::any y) override;

            void setSortColumn(int value);
            int getSortColumn() const;

            void setOrder(SortOrder *value);
            SortOrder *getOrder() const;

        };
    private:
        Timer *const _itemSelectionChangedTimer = new Timer();
        Timer *const _selectedIndexChangedTimer = new Timer();

        ListViewItemSelectionChangedEventArgs *_itemSelectionChangedEventArgs;
        EventArgs *_selectedIndexChangedEventArgs;
        ListViewColumnSorter *const _sorter;

    public:
        virtual ~ListViewNF()
        {
            delete _itemSelectionChangedTimer;
            delete _selectedIndexChangedTimer;
            delete _itemSelectionChangedEventArgs;
            delete _selectedIndexChangedEventArgs;
            delete _sorter;
        }

        ListViewNF();

    private:
        void ListViewNF_ColumnClick(std::any sender, ColumnClickEventArgs *e);

    protected:
        void OnNotifyMessage(Message *m) override;



        void OnItemSelectionChanged(ListViewItemSelectionChangedEventArgs *e) override;

        void OnSelectedIndexChanged(EventArgs *e) override;

    };
}
